package com.zklh.leetcode.top100;

/**
 * 寻找旋转排序数组中的最小值算法实现
 *  // 这里是使用二分查找 找首位连接处, 连接处 一定是两者相邻, 且nums[left] > nums[right]
 * @version 1.0
 * @Author tongnan
 * @Date 2023/11/22
 */
public class Solution153 {
    public int findMin(int[] nums) {
        if (nums[0] <= nums[nums.length-1]) {
            return nums[0];
        }
        int left = 0, right = nums.length-1;
        while (left < right - 1) {
            int mid = (left + right) / 2;
            if (nums[left] < nums[mid]) {
                left = mid;
            } else if (nums[mid] < nums[right]) {
                right = mid;
            }
        }
        return nums[right];
    }

    public static void main(String[] args) {
        Solution153 solution153 = new Solution153();
        int[] nums = {11,13,15,17};
        System.out.println(solution153.findMin(nums));
    }
}